#include <QPainter>
#include <QWidget>
#include <QDebug>
#include "ProgressRing.h"

ProgressRing::ProgressRing(QWidget *parent) :
	QWidget(parent), m_img("://resource/image/progress_01.png"),
	m_iTimerID(0)
{
}

void ProgressRing::SlotProgressStart()
{
	QWidget *pWdt = this->parentWidget();
	this->setGeometry(QRect(QPoint(0, 0), pWdt->size()));
	qDebug() << this->geometry() << pWdt->geometry();
	this->setWindowModality(Qt::ApplicationModal);
	this->show();
	m_iRot = 0;
	m_iTimerID = this->startTimer(1000);
}

void ProgressRing::SlotProgressEnd()
{
	this->killTimer(m_iTimerID);
	this->hide();
}

void ProgressRing::paintEvent(QPaintEvent *event)
{
	Q_UNUSED(event);

	QPainter painter(this);
	QPoint center(this->rect().center());
	QRect rect(m_img.rect());

	painter.fillRect(this->rect(), Qt::transparent);
	rect.moveCenter(center);
	painter.translate(center);
	painter.rotate(m_iRot);
	painter.translate(-center);
	painter.drawImage(rect, m_img);
}

void ProgressRing::timerEvent(QTimerEvent *event)
{
	m_iRot += 30;
	this->update();
}
